

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>pysimm.calc &mdash; pysimm 0.2 documentation</title>
  

  
  

  

  
  
    

  

  
  
    <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  

  

  
    <link rel="top" title="pysimm 0.2 documentation" href="../../index.html"/>
        <link rel="up" title="pysimm" href="../pysimm.html"/> 

  
  <script src="../../_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="../../index.html" class="icon icon-home"> pysimm
          

          
          </a>

          
            
            
              <div class="version">
                0.2
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
                <ul>
<li class="toctree-l1"><a class="reference internal" href="../../pysimm.html">pysimm package</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="../../index.html">pysimm</a>
      </nav>


      
      <div class="wy-nav-content">
        <div class="rst-content">
          





<div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="../../index.html">Docs</a> &raquo;</li>
      
          <li><a href="../index.html">Module code</a> &raquo;</li>
      
          <li><a href="../pysimm.html">pysimm</a> &raquo;</li>
      
    <li>pysimm.calc</li>
      <li class="wy-breadcrumbs-aside">
        
          
        
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for pysimm.calc</h1><div class="highlight"><pre>
<span></span><span class="c1"># ******************************************************************************</span>
<span class="c1"># pysimm.calc module</span>
<span class="c1"># ******************************************************************************</span>
<span class="c1">#</span>
<span class="c1"># ******************************************************************************</span>
<span class="c1"># License</span>
<span class="c1"># ******************************************************************************</span>
<span class="c1"># The MIT License (MIT)</span>
<span class="c1">#</span>
<span class="c1"># Copyright (c) 2016 Michael E. Fortunato, Coray M. Colina</span>
<span class="c1">#</span>
<span class="c1"># Permission is hereby granted, free of charge, to any person obtaining a copy</span>
<span class="c1"># of this software and associated documentation files (the &quot;Software&quot;), to deal</span>
<span class="c1"># in the Software without restriction, including without limitation the rights</span>
<span class="c1"># to use, copy, modify, merge, publish, distribute, sublicense, and/or sell</span>
<span class="c1"># copies of the Software, and to permit persons to whom the Software is</span>
<span class="c1"># furnished to do so, subject to the following conditions:</span>
<span class="c1">#</span>
<span class="c1"># The above copyright notice and this permission notice shall be included in</span>
<span class="c1"># all copies or substantial portions of the Software.</span>
<span class="c1">#</span>
<span class="c1"># THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR</span>
<span class="c1"># IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span>
<span class="c1"># FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE</span>
<span class="c1"># AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span>
<span class="c1"># LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,</span>
<span class="c1"># OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN</span>
<span class="c1"># THE SOFTWARE.</span>

<span class="kn">from</span> <span class="nn">random</span> <span class="kn">import</span> <span class="n">random</span>
<span class="kn">from</span> <span class="nn">itertools</span> <span class="kn">import</span> <span class="n">izip</span>
<span class="kn">from</span> <span class="nn">math</span> <span class="kn">import</span> <span class="n">sin</span><span class="p">,</span> <span class="n">cos</span><span class="p">,</span> <span class="n">pi</span><span class="p">,</span> <span class="n">acos</span>
<span class="k">try</span><span class="p">:</span>
    <span class="kn">import</span> <span class="nn">numpy</span> <span class="kn">as</span> <span class="nn">np</span>
<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
    <span class="n">np</span> <span class="o">=</span> <span class="bp">None</span>

<span class="kn">from</span> <span class="nn">pysimm</span> <span class="kn">import</span> <span class="n">error_print</span>
<span class="kn">from</span> <span class="nn">pysimm</span> <span class="kn">import</span> <span class="n">warning_print</span>
<span class="kn">from</span> <span class="nn">pysimm</span> <span class="kn">import</span> <span class="n">verbose_print</span>
<span class="kn">from</span> <span class="nn">pysimm</span> <span class="kn">import</span> <span class="n">debug_print</span>
<span class="kn">from</span> <span class="nn">pysimm</span> <span class="kn">import</span> <span class="n">PysimmError</span>
<span class="kn">from</span> <span class="nn">pysimm.utils</span> <span class="kn">import</span> <span class="n">Item</span>
<span class="kn">from</span> <span class="nn">pysimm.utils</span> <span class="kn">import</span> <span class="n">ItemContainer</span>


<div class="viewcode-block" id="intersection"><a class="viewcode-back" href="../../pysimm.calc.html#pysimm.calc.intersection">[docs]</a><span class="k">def</span> <span class="nf">intersection</span><span class="p">(</span><span class="n">line1</span><span class="p">,</span> <span class="n">line2</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.calc.intersection</span>

<span class="sd">    Finds intersection between two 2D lines given by two sets of points</span>

<span class="sd">    Args:</span>
<span class="sd">        line1: [[x1,y1], [x2,y2]] for line 1</span>
<span class="sd">        line2: [[x1,y1], [x2,y2]] for line 2</span>
<span class="sd">    Returns:</span>
<span class="sd">        x,y intersection point</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">xdiff</span> <span class="o">=</span> <span class="p">(</span><span class="n">line1</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">line1</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="n">line2</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">line2</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span>
    <span class="n">ydiff</span> <span class="o">=</span> <span class="p">(</span><span class="n">line1</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">line1</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">],</span> <span class="n">line2</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">line2</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span>

    <span class="k">def</span> <span class="nf">det</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">a</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">b</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">a</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="n">b</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

    <span class="n">div</span> <span class="o">=</span> <span class="n">det</span><span class="p">(</span><span class="n">xdiff</span><span class="p">,</span> <span class="n">ydiff</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">div</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
        <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s1">&#39;lines do not intersect&#39;</span><span class="p">)</span>

    <span class="n">d</span> <span class="o">=</span> <span class="p">(</span><span class="n">det</span><span class="p">(</span><span class="o">*</span><span class="n">line1</span><span class="p">),</span> <span class="n">det</span><span class="p">(</span><span class="o">*</span><span class="n">line2</span><span class="p">))</span>
    <span class="n">x</span> <span class="o">=</span> <span class="n">det</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="n">xdiff</span><span class="p">)</span> <span class="o">/</span> <span class="n">div</span>
    <span class="n">y</span> <span class="o">=</span> <span class="n">det</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="n">ydiff</span><span class="p">)</span> <span class="o">/</span> <span class="n">div</span>
    <span class="k">return</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span></div>


<div class="viewcode-block" id="find_rotation"><a class="viewcode-back" href="../../pysimm.calc.html#pysimm.calc.find_rotation">[docs]</a><span class="k">def</span> <span class="nf">find_rotation</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.calc.find_rotation</span>

<span class="sd">    Finds rotation vector required to align vector a and vector b</span>

<span class="sd">    Args:</span>
<span class="sd">        a: 3D vector [x,y,z]</span>
<span class="sd">        b: 3D vector [x,y,z]</span>
<span class="sd">    Returns:</span>
<span class="sd">        rotation matrix</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">np</span><span class="p">:</span>
        <span class="k">raise</span> <span class="n">PysimmError</span><span class="p">(</span><span class="s1">&#39;pysimm.calc.find_rotation function requires numpy&#39;</span><span class="p">)</span>
    <span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
    <span class="n">b</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">b</span><span class="p">)</span>

    <span class="n">a_x_b</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">cross</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
    <span class="n">axis</span> <span class="o">=</span> <span class="n">a_x_b</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">a_x_b</span><span class="p">)</span>

    <span class="n">theta</span> <span class="o">=</span> <span class="n">acos</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">a</span><span class="p">)</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">b</span><span class="p">))</span>

    <span class="n">skew</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">matrix</span><span class="p">([[</span><span class="mi">0</span><span class="p">,</span> <span class="o">-</span><span class="n">axis</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">axis</span><span class="p">[</span><span class="mi">1</span><span class="p">]],</span>
                     <span class="p">[</span><span class="n">axis</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="mi">0</span><span class="p">,</span> <span class="o">-</span><span class="n">axis</span><span class="p">[</span><span class="mi">0</span><span class="p">]],</span>
                     <span class="p">[</span><span class="o">-</span><span class="n">axis</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">axis</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="mi">0</span><span class="p">]])</span>

    <span class="n">rot_matrix</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">identity</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">+</span> <span class="n">sin</span><span class="p">(</span><span class="n">theta</span><span class="p">)</span><span class="o">*</span><span class="n">skew</span> <span class="o">+</span> <span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">cos</span><span class="p">(</span><span class="n">theta</span><span class="p">))</span><span class="o">*</span><span class="n">skew</span><span class="o">*</span><span class="n">skew</span>

    <span class="k">return</span> <span class="n">rot_matrix</span></div>


<div class="viewcode-block" id="rotate_vector"><a class="viewcode-back" href="../../pysimm.calc.html#pysimm.calc.rotate_vector">[docs]</a><span class="k">def</span> <span class="nf">rotate_vector</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">,</span> <span class="n">theta_x</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">theta_y</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">theta_z</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.calc.rotate_vector</span>

<span class="sd">    Rotates 3d vector around x-axis, y-axis and z-axis given by user defined angles</span>

<span class="sd">    Args:</span>
<span class="sd">        x: x vector component</span>
<span class="sd">        y: y vector component</span>
<span class="sd">        z: z vector component</span>
<span class="sd">        theta_x: angle to rotate vector around x axis</span>
<span class="sd">        theta_y: angle to rotate vector around y axis</span>
<span class="sd">        theta_z: angle to rotate vector around z axis</span>
<span class="sd">    Returns:</span>
<span class="sd">        new vector [x,y,z]</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">np</span><span class="p">:</span>
        <span class="k">raise</span> <span class="n">PysimmError</span><span class="p">(</span><span class="s1">&#39;pysimm.calc.rotate_vector function requires numpy&#39;</span><span class="p">)</span>
    <span class="n">xt</span> <span class="o">=</span> <span class="n">random</span><span class="p">()</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">pi</span> <span class="k">if</span> <span class="n">theta_x</span> <span class="ow">is</span> <span class="bp">None</span> <span class="k">else</span> <span class="n">theta_x</span>
    <span class="n">yt</span> <span class="o">=</span> <span class="n">random</span><span class="p">()</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">pi</span> <span class="k">if</span> <span class="n">theta_y</span> <span class="ow">is</span> <span class="bp">None</span> <span class="k">else</span> <span class="n">theta_y</span>
    <span class="n">zt</span> <span class="o">=</span> <span class="n">random</span><span class="p">()</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">pi</span> <span class="k">if</span> <span class="n">theta_z</span> <span class="ow">is</span> <span class="bp">None</span> <span class="k">else</span> <span class="n">theta_z</span>

    <span class="n">c</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">matrix</span><span class="p">([[</span><span class="n">x</span><span class="p">],</span> <span class="p">[</span><span class="n">y</span><span class="p">],</span> <span class="p">[</span><span class="n">z</span><span class="p">]])</span>

    <span class="n">rot_mat_x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
                           <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="n">cos</span><span class="p">(</span><span class="n">xt</span><span class="p">),</span> <span class="o">-</span><span class="n">sin</span><span class="p">(</span><span class="n">xt</span><span class="p">)],</span>
                           <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="n">sin</span><span class="p">(</span><span class="n">xt</span><span class="p">),</span> <span class="n">cos</span><span class="p">(</span><span class="n">xt</span><span class="p">)]])</span>
    <span class="n">rot_mat_y</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">matrix</span><span class="p">([[</span><span class="n">cos</span><span class="p">(</span><span class="n">yt</span><span class="p">),</span> <span class="mi">0</span><span class="p">,</span> <span class="n">sin</span><span class="p">(</span><span class="n">yt</span><span class="p">)],</span>
                           <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
                           <span class="p">[</span><span class="o">-</span><span class="n">sin</span><span class="p">(</span><span class="n">yt</span><span class="p">),</span> <span class="mi">0</span><span class="p">,</span> <span class="n">cos</span><span class="p">(</span><span class="n">yt</span><span class="p">)]])</span>
    <span class="n">rot_mat_z</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">matrix</span><span class="p">([[</span><span class="n">cos</span><span class="p">(</span><span class="n">zt</span><span class="p">),</span> <span class="o">-</span><span class="n">sin</span><span class="p">(</span><span class="n">zt</span><span class="p">),</span> <span class="mi">0</span><span class="p">],</span>
                           <span class="p">[</span><span class="n">sin</span><span class="p">(</span><span class="n">zt</span><span class="p">),</span> <span class="n">cos</span><span class="p">(</span><span class="n">zt</span><span class="p">),</span> <span class="mi">0</span><span class="p">],</span>
                           <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span>

    <span class="n">c</span> <span class="o">=</span> <span class="n">rot_mat_x</span> <span class="o">*</span> <span class="n">c</span>
    <span class="n">c</span> <span class="o">=</span> <span class="n">rot_mat_y</span> <span class="o">*</span> <span class="n">c</span>
    <span class="n">c</span> <span class="o">=</span> <span class="n">rot_mat_z</span> <span class="o">*</span> <span class="n">c</span>

    <span class="k">return</span> <span class="p">[</span><span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">c</span><span class="o">.</span><span class="n">tolist</span><span class="p">()]</span></div>


<div class="viewcode-block" id="distance"><a class="viewcode-back" href="../../pysimm.calc.html#pysimm.calc.distance">[docs]</a><span class="k">def</span> <span class="nf">distance</span><span class="p">(</span><span class="n">p1</span><span class="p">,</span> <span class="n">p2</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.calc.distance</span>

<span class="sd">    Finds distance between two :class:`~pysimm.system.Particle` objects. Simply calculates length of vector between particle coordinates and does not consider periodic boundary conditions.</span>

<span class="sd">    Args:</span>
<span class="sd">        p1: :class:`~pysimm.system.Particle`</span>
<span class="sd">        p2: :class:`~pysimm.system.Particle`</span>
<span class="sd">    Returns:</span>
<span class="sd">        distance between particles</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">np</span><span class="p">:</span>
        <span class="k">raise</span> <span class="n">PysimmError</span><span class="p">(</span><span class="s1">&#39;pysimm.calc.distance function requires numpy&#39;</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">([</span><span class="n">p1</span><span class="o">.</span><span class="n">x</span> <span class="o">-</span> <span class="n">p2</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">p1</span><span class="o">.</span><span class="n">y</span> <span class="o">-</span> <span class="n">p2</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="n">p1</span><span class="o">.</span><span class="n">z</span> <span class="o">-</span> <span class="n">p2</span><span class="o">.</span><span class="n">z</span><span class="p">])</span></div>


<div class="viewcode-block" id="angle"><a class="viewcode-back" href="../../pysimm.calc.html#pysimm.calc.angle">[docs]</a><span class="k">def</span> <span class="nf">angle</span><span class="p">(</span><span class="n">p1</span><span class="p">,</span> <span class="n">p2</span><span class="p">,</span> <span class="n">p3</span><span class="p">,</span> <span class="n">radians</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.calc.angle</span>

<span class="sd">    Finds angle between three :class:`~pysimm.system.Particle` objects. Does not consider periodic boundary conditions.</span>

<span class="sd">    Args:</span>
<span class="sd">        p1: pysimm.system.Particle</span>
<span class="sd">        p2: pysimm.system.Particle</span>
<span class="sd">        p3: pysimm.system.Particle</span>
<span class="sd">        radians: returns value in radians if True (False)</span>
<span class="sd">    Returns:</span>
<span class="sd">        angle between particles</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">p12</span> <span class="o">=</span> <span class="n">distance</span><span class="p">(</span><span class="n">p1</span><span class="p">,</span> <span class="n">p2</span><span class="p">)</span>
    <span class="n">p23</span> <span class="o">=</span> <span class="n">distance</span><span class="p">(</span><span class="n">p2</span><span class="p">,</span> <span class="n">p3</span><span class="p">)</span>
    <span class="n">p13</span> <span class="o">=</span> <span class="n">distance</span><span class="p">(</span><span class="n">p1</span><span class="p">,</span> <span class="n">p3</span><span class="p">)</span>
    <span class="n">theta</span> <span class="o">=</span> <span class="n">acos</span><span class="p">((</span><span class="nb">pow</span><span class="p">(</span><span class="n">p12</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span><span class="o">+</span><span class="nb">pow</span><span class="p">(</span><span class="n">p23</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span><span class="o">-</span><span class="nb">pow</span><span class="p">(</span><span class="n">p13</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span><span class="o">/</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">p12</span><span class="o">*</span><span class="n">p23</span><span class="p">))</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">radians</span><span class="p">:</span>
        <span class="n">theta</span> <span class="o">=</span> <span class="n">theta</span> <span class="o">*</span> <span class="mi">180</span> <span class="o">/</span> <span class="n">pi</span>
    <span class="k">return</span> <span class="n">theta</span></div>


<div class="viewcode-block" id="chiral_angle"><a class="viewcode-back" href="../../pysimm.calc.html#pysimm.calc.chiral_angle">[docs]</a><span class="k">def</span> <span class="nf">chiral_angle</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.calc.chiral_angle</span>

<span class="sd">    Finds chiral angle between four :class:`~pysimm.system.Particle` objects. Chiral angle is defined as the angle between the vector resulting from vec(a-&gt;c) X vec(a-&gt;d) and vec(a-&gt;b). Used to help define tacticity where backbone follow b&#39;--a--b and c and d are side groups.</span>
<span class="sd">           </span>
<span class="sd">       b&#39;--a--b</span>
<span class="sd">          / \</span>
<span class="sd">         c   d</span>
<span class="sd">    </span>
<span class="sd">    Args:</span>
<span class="sd">        a: pysimm.system.Particle</span>
<span class="sd">        b: pysimm.system.Particle</span>
<span class="sd">        c: pysimm.system.Particle</span>
<span class="sd">        d: pysimm.system.Particle</span>
<span class="sd">    Returns:</span>
<span class="sd">        chiral angle</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">np</span><span class="p">:</span>
        <span class="k">raise</span> <span class="n">PysimmError</span><span class="p">(</span><span class="s1">&#39;pysimm.calc.chiral_angle function requires numpy&#39;</span><span class="p">)</span>
    <span class="n">ht</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">a</span><span class="o">.</span><span class="n">x</span><span class="o">-</span><span class="n">b</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">a</span><span class="o">.</span><span class="n">y</span><span class="o">-</span><span class="n">b</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="n">a</span><span class="o">.</span><span class="n">z</span><span class="o">-</span><span class="n">b</span><span class="o">.</span><span class="n">z</span><span class="p">])</span>
    <span class="n">ht</span> <span class="o">/=</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">ht</span><span class="p">)</span>

    <span class="n">hmethyl</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">a</span><span class="o">.</span><span class="n">x</span><span class="o">-</span><span class="n">d</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">a</span><span class="o">.</span><span class="n">y</span><span class="o">-</span><span class="n">d</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="n">a</span><span class="o">.</span><span class="n">z</span><span class="o">-</span><span class="n">d</span><span class="o">.</span><span class="n">z</span><span class="p">])</span>
    <span class="n">hmethyl</span> <span class="o">/=</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">hmethyl</span><span class="p">)</span>

    <span class="n">hside</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">a</span><span class="o">.</span><span class="n">x</span><span class="o">-</span><span class="n">c</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">a</span><span class="o">.</span><span class="n">y</span><span class="o">-</span><span class="n">c</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="n">a</span><span class="o">.</span><span class="n">z</span><span class="o">-</span><span class="n">c</span><span class="o">.</span><span class="n">z</span><span class="p">])</span>
    <span class="n">hside</span> <span class="o">/=</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">hside</span><span class="p">)</span>

    <span class="n">side_x_methyl</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">cross</span><span class="p">(</span><span class="n">hside</span><span class="p">,</span> <span class="n">hmethyl</span><span class="p">)</span>

    <span class="n">side_dot_methyl</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">hside</span><span class="p">,</span> <span class="n">hmethyl</span><span class="p">)</span>
    <span class="n">side_theta_methyl</span> <span class="o">=</span> <span class="n">acos</span><span class="p">(</span><span class="n">side_dot_methyl</span><span class="p">)</span>

    <span class="n">side_x_methyl</span> <span class="o">/=</span> <span class="n">sin</span><span class="p">(</span><span class="n">side_theta_methyl</span><span class="p">)</span>

    <span class="n">cos_theta</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">side_x_methyl</span><span class="p">,</span> <span class="n">ht</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">acos</span><span class="p">(</span><span class="n">cos_theta</span><span class="p">)</span><span class="o">/</span><span class="n">pi</span><span class="o">*</span><span class="mi">180</span></div>


<div class="viewcode-block" id="tacticity"><a class="viewcode-back" href="../../pysimm.calc.html#pysimm.calc.tacticity">[docs]</a><span class="k">def</span> <span class="nf">tacticity</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">a_tag</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">b_tag</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">c_tag</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">d_tag</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">offset</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">return_angles</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">unwrap</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span>
              <span class="n">rewrap</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">skip_first</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.calc.tacticity</span>

<span class="sd">    Determines tacticity for polymer chain. Iterates through groups of four patricles given by X_tags, using offset. This assumes equivalent atoms in each group of four are perfectly offset.</span>

<span class="sd">    Args:</span>
<span class="sd">        s: :class:`~pysimm.system.System`</span>
<span class="sd">        a_tag: tag of first a particle</span>
<span class="sd">        b_tag: tag of first b particle</span>
<span class="sd">        c_tag: tag of first c particle</span>
<span class="sd">        d_tag: tag of first d particle</span>
<span class="sd">        offset: offset of particle tags (monomer repeat atomic count)</span>
<span class="sd">        return_angles: if True return chiral angles of all monomers</span>
<span class="sd">        unwrap: True to perform unwrap before calculation (REQUIRED before calculation, but not required in this</span>
<span class="sd">        function)</span>
<span class="sd">        rewrap: True to rewrap system after calculation</span>
<span class="sd">        skip_first: True to skip first monomer (sometime chirality is poorly defined for thsi monomer)</span>
<span class="sd">    Returns:</span>
<span class="sd">        tacticity or tacticity, [chiral_angles]</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">np</span><span class="p">:</span>
        <span class="k">raise</span> <span class="n">PysimmError</span><span class="p">(</span><span class="s1">&#39;pysimm.calc.tacticity function requires numpy&#39;</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">a_tag</span> <span class="ow">is</span> <span class="bp">None</span> <span class="ow">or</span> <span class="n">b_tag</span> <span class="ow">is</span> <span class="bp">None</span> <span class="ow">or</span> <span class="n">c_tag</span> <span class="ow">is</span> <span class="bp">None</span> <span class="ow">or</span> <span class="n">d_tag</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
        <span class="n">error_print</span><span class="p">(</span><span class="s1">&#39;particle tags for chiral center are required&#39;</span><span class="p">)</span>
        <span class="n">error_print</span><span class="p">(</span><span class="s1">&#39;a: chiral center, b-d: 3 side groups&#39;</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">offset</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
        <span class="n">error_print</span><span class="p">(</span><span class="s1">&#39;offset for tags in each monomer is required, i.e. - number of particles in each monomer&#39;</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">unwrap</span><span class="p">:</span>
        <span class="n">s</span><span class="o">.</span><span class="n">unwrap</span><span class="p">()</span>

    <span class="n">a_</span> <span class="o">=</span> <span class="p">[</span><span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">a_tag</span><span class="p">,</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">count</span><span class="p">,</span> <span class="n">offset</span><span class="p">)]</span>
    <span class="n">b_</span> <span class="o">=</span> <span class="p">[</span><span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">b_tag</span><span class="p">,</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">count</span><span class="p">,</span> <span class="n">offset</span><span class="p">)]</span>
    <span class="n">c_</span> <span class="o">=</span> <span class="p">[</span><span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">c_tag</span><span class="p">,</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">count</span><span class="p">,</span> <span class="n">offset</span><span class="p">)]</span>
    <span class="n">d_</span> <span class="o">=</span> <span class="p">[</span><span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">d_tag</span><span class="p">,</span> <span class="n">s</span><span class="o">.</span><span class="n">particles</span><span class="o">.</span><span class="n">count</span><span class="p">,</span> <span class="n">offset</span><span class="p">)]</span>

    <span class="n">stereochem_angles</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="k">if</span> <span class="n">skip_first</span><span class="p">:</span>
        <span class="k">for</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">izip</span><span class="p">(</span><span class="n">a_</span><span class="p">[</span><span class="mi">1</span><span class="p">:],</span> <span class="n">b_</span><span class="p">[</span><span class="mi">1</span><span class="p">:],</span> <span class="n">c_</span><span class="p">[</span><span class="mi">1</span><span class="p">:],</span> <span class="n">d_</span><span class="p">[</span><span class="mi">1</span><span class="p">:]):</span>
            <span class="n">stereochem_angles</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">chiral_angle</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">))</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">for</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">izip</span><span class="p">(</span><span class="n">a_</span><span class="p">,</span> <span class="n">b_</span><span class="p">,</span> <span class="n">c_</span><span class="p">,</span> <span class="n">d_</span><span class="p">):</span>
            <span class="n">stereochem_angles</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">chiral_angle</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">))</span>

    <span class="n">last</span> <span class="o">=</span> <span class="bp">None</span>
    <span class="n">iso_diads</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="n">syn_diads</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="n">stereochem_angles</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">last</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="p">(</span><span class="n">a</span> <span class="o">&lt;</span> <span class="mi">90</span> <span class="ow">and</span> <span class="n">last</span> <span class="o">&lt;</span> <span class="mi">90</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span><span class="n">a</span> <span class="o">&gt;</span> <span class="mi">90</span> <span class="ow">and</span> <span class="n">last</span> <span class="o">&gt;</span> <span class="mi">90</span><span class="p">):</span>
                <span class="n">iso_diads</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">syn_diads</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="n">last</span> <span class="o">=</span> <span class="n">a</span>

    <span class="k">if</span> <span class="n">iso_diads</span> <span class="o">==</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">stereochem_angles</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">):</span>
        <span class="n">t</span> <span class="o">=</span> <span class="s1">&#39;isotactic&#39;</span>
    <span class="k">elif</span> <span class="n">syn_diads</span> <span class="o">==</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">stereochem_angles</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">):</span>
        <span class="n">t</span> <span class="o">=</span> <span class="s1">&#39;syndiotactic&#39;</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">t</span> <span class="o">=</span> <span class="s1">&#39;atactic&#39;</span>

    <span class="k">if</span> <span class="n">rewrap</span><span class="p">:</span>
        <span class="n">s</span><span class="o">.</span><span class="n">wrap</span><span class="p">()</span>

    <span class="k">print</span><span class="p">(</span><span class="s1">&#39;{:.1f}</span><span class="si">% s</span><span class="s1">yn diads&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="mi">100</span><span class="o">*</span><span class="nb">float</span><span class="p">(</span><span class="n">syn_diads</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="n">syn_diads</span><span class="o">+</span><span class="n">iso_diads</span><span class="p">)))</span>
    <span class="k">print</span><span class="p">(</span><span class="s1">&#39;{:.1f}</span><span class="si">% i</span><span class="s1">so diads&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="mi">100</span><span class="o">*</span><span class="nb">float</span><span class="p">(</span><span class="n">iso_diads</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="n">syn_diads</span><span class="o">+</span><span class="n">iso_diads</span><span class="p">)))</span>
    <span class="k">if</span> <span class="n">return_angles</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">t</span><span class="p">,</span> <span class="n">stereochem_angles</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">t</span></div>


<div class="viewcode-block" id="frac_free_volume"><a class="viewcode-back" href="../../pysimm.calc.html#pysimm.calc.frac_free_volume">[docs]</a><span class="k">def</span> <span class="nf">frac_free_volume</span><span class="p">(</span><span class="n">v_sp</span><span class="p">,</span> <span class="n">v_void</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.calc.frac_free_volume</span>

<span class="sd">    Determines fractional free volume for a poroous system.</span>

<span class="sd">    Args:</span>
<span class="sd">        v_sp: specific volume</span>
<span class="sd">        v_void: void volume</span>
<span class="sd">    Returns:</span>
<span class="sd">        fractional free volume</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="p">(</span><span class="o">-</span><span class="mf">0.3</span> <span class="o">*</span> <span class="n">v_sp</span> <span class="o">+</span> <span class="mf">1.3</span> <span class="o">*</span> <span class="n">v_void</span><span class="p">)</span><span class="o">/</span><span class="n">v_sp</span></div>


<div class="viewcode-block" id="pbc_distance"><a class="viewcode-back" href="../../pysimm.calc.html#pysimm.calc.pbc_distance">[docs]</a><span class="k">def</span> <span class="nf">pbc_distance</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">p1</span><span class="p">,</span> <span class="n">p2</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;pysimm.calc.pbc_distance</span>

<span class="sd">    Calculates distance between particles using PBC</span>

<span class="sd">    Args:</span>
<span class="sd">        s: :class:`~pysimm.system.System`</span>
<span class="sd">        p1: :class:`~pysimm.system.Particle`</span>
<span class="sd">        p2: :class:`~pysimm.system.Particle`</span>
<span class="sd">    Returns:</span>
<span class="sd">        distance between particles</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">np</span><span class="p">:</span>
        <span class="k">raise</span> <span class="n">PysimmError</span><span class="p">(</span><span class="s1">&#39;pysimm.calc.pbc_distance function requires numpy&#39;</span><span class="p">)</span>
    <span class="n">frac_x1</span> <span class="o">=</span> <span class="n">p1</span><span class="o">.</span><span class="n">x</span> <span class="o">/</span> <span class="n">s</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dx</span>
    <span class="n">frac_y1</span> <span class="o">=</span> <span class="n">p1</span><span class="o">.</span><span class="n">y</span> <span class="o">/</span> <span class="n">s</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dy</span>
    <span class="n">frac_z1</span> <span class="o">=</span> <span class="n">p1</span><span class="o">.</span><span class="n">z</span> <span class="o">/</span> <span class="n">s</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dz</span>

    <span class="n">frac_x2</span> <span class="o">=</span> <span class="n">p2</span><span class="o">.</span><span class="n">x</span> <span class="o">/</span> <span class="n">s</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dx</span>
    <span class="n">frac_y2</span> <span class="o">=</span> <span class="n">p2</span><span class="o">.</span><span class="n">y</span> <span class="o">/</span> <span class="n">s</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dy</span>
    <span class="n">frac_z2</span> <span class="o">=</span> <span class="n">p2</span><span class="o">.</span><span class="n">z</span> <span class="o">/</span> <span class="n">s</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dz</span>

    <span class="n">frac_d</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">frac_x1</span> <span class="o">-</span> <span class="n">frac_x2</span><span class="p">,</span> <span class="n">frac_y1</span> <span class="o">-</span> <span class="n">frac_y2</span><span class="p">,</span> <span class="n">frac_z1</span> <span class="o">-</span> <span class="n">frac_z2</span><span class="p">])</span>
    <span class="n">frac_d</span> <span class="o">=</span> <span class="n">frac_d</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="n">frac_d</span><span class="p">)</span>

    <span class="n">dx</span> <span class="o">=</span> <span class="n">frac_d</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">s</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dx</span>
    <span class="n">dy</span> <span class="o">=</span> <span class="n">frac_d</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="n">s</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dy</span>
    <span class="n">dz</span> <span class="o">=</span> <span class="n">frac_d</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">*</span> <span class="n">s</span><span class="o">.</span><span class="n">dim</span><span class="o">.</span><span class="n">dz</span>

    <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">([</span><span class="n">dx</span><span class="p">,</span> <span class="n">dy</span><span class="p">,</span> <span class="n">dz</span><span class="p">])</span></div>
</pre></div>

           </div>
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2017, https://pysimm.org.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'../../',
            VERSION:'0.2',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true
        };
    </script>
      <script type="text/javascript" src="../../_static/jquery.js"></script>
      <script type="text/javascript" src="../../_static/underscore.js"></script>
      <script type="text/javascript" src="../../_static/doctools.js"></script>

  

  
  
    <script type="text/javascript" src="../../_static/js/theme.js"></script>
  

  
  
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.StickyNav.enable();
      });
  </script>
   

</body>
</html>